﻿//using Plugin.BLE;
//using Plugin.BLE.Abstractions.Contracts;
//using Plugin.BLE.Abstractions.EventArgs;
//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;

//namespace CommonLibrary.BLE
//{
//    public class BLECore
//    {
//        private static IBluetoothLE BLE;
//        private static IAdapter Adapter;

//        public Action<IDevice> DeviceDiscovered;

//        public void Initialize()
//        {
//            BLE ??= CrossBluetoothLE.Current;
//            Adapter ??= BLE.Adapter;

//            BLE.StateChanged += OnStateChanged;
//            Adapter.DeviceDiscovered += OnDeviceDiscovered;
//            Adapter.DeviceAdvertised += OnDeviceDiscovered;
//            Adapter.ScanTimeoutElapsed += Adapter_ScanTimeoutElapsed;
//            Adapter.DeviceDisconnected += OnDeviceDisconnected;
//            Adapter.DeviceConnectionLost += OnDeviceConnectionLost;

//            Adapter.ScanMode = ScanMode.LowLatency;
//        }

//        //MyViewModel(IBluetoothLE ble, IAdapter adapter)
//        //{
//        //    this.ble = ble;
//        //    this.adapter = adapter;
//        //}

//        public async Task Scan()
//        {
//            //Plugin.BLE.Abstractions.ScanFilterOptions
//            await Adapter.StartScanningForDevicesAsync();
//        }

//        private void OnStateChanged(object sender, BluetoothStateChangedArgs e)
//        {
//            //TryStartScanning();
//        }

//        /// <summary>
//        /// 设备发现
//        /// </summary>
//        /// <param name="sender"></param>
//        /// <param name="args"></param>
//        private void OnDeviceDiscovered(object sender, DeviceEventArgs args)
//        {
//            DeviceDiscovered?.Invoke(args.Device);
//        }

//        /// <summary>
//        /// 扫描超时
//        /// </summary>
//        /// <param name="sender"></param>
//        /// <param name="e"></param>
//        private void Adapter_ScanTimeoutElapsed(object sender, EventArgs e)
//        {

//        }

//        /// <summary>
//        /// 设备断开
//        /// </summary>
//        /// <param name="sender"></param>
//        /// <param name="e"></param>
//        private void OnDeviceDisconnected(object sender, DeviceEventArgs e)
//        {

//        }

//        /// <summary>
//        /// 设备连接丢失
//        /// </summary>
//        /// <param name="sender"></param>
//        /// <param name="e"></param>
//        private void OnDeviceConnectionLost(object sender, DeviceErrorEventArgs e)
//        {

//        }

//    }
//}